/*
 * @lc app=leetcode.cn id=415 lang=typescript
 *
 * [415] 字符串相加
 */

// @lc code=start
function addStrings(num1: string, num2: string): string {
    const a = num1.split("");
    const b = num2.split("");
    let c = Math.max(a.length, b.length);
    let plus = 0;
    let final = "";
    for (let i = 1; i < c + 1; i++) {
        const num1 = parseInt(a[a.length - i] || "0");
        const num2 = parseInt(b[b.length - i] || "0");
        let result = num1 + num2 + plus;
        plus = 0;
        if (result > 9) {
            plus = 1;
            result -= 10;
        }
        final = result.toString() + final;
    }
    if (plus) {
        return "1" + final;
    } else {
        return final;
    }
}
// @lc code=end
